package ee.greaton.kultuuriaken;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class WebViewActivity extends Activity {
	static String url = null;

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.web);
		
		WebView webview = (WebView) findViewById(R.id.webView);
		
		Intent intent = getIntent();
		url = (String) intent
				.getStringExtra(EventViewActivity.SINGLE_URL_EXTRA);
		
		final ProgressBar Pbar = (ProgressBar) findViewById(R.id.progressBar);;
		Pbar.setVisibility(ProgressBar.VISIBLE);

		webview.setWebChromeClient(new WebChromeClient() {
		    public void onProgressChanged(WebView view, int progress) {
		    	Pbar.setProgress(progress);
		    	if(progress == 100) {
                    Pbar.setVisibility(ProgressBar.GONE);
                }
		    }
		});
		
		webview.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				if (url.equals(WebViewActivity.url)) {
					view.clearHistory();
				}
			}
		});
		
		webview.getSettings().setJavaScriptEnabled(true);
		webview.loadUrl(url);
	}
}
